using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using buildingLib.Administration;
namespace _dmis.fixedasset
{
    public partial class FixedAssetInDlg : _dmis.UIFormBase
    {
        FixedAssets m_assets;
        buildingLib.Administration.FixedAssetsIn m_assetsin;
        public FixedAssetInDlg()
        {
            InitializeComponent();
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            FixedAssert fa = this.fixedAssetsBindingSource.Current as FixedAssert;
            if (fa != null)
            {
                m_assets.Remove(fa);
                m_assetsin.Add(fa);
            }
        }

        private void btn_Remove_Click(object sender, EventArgs e)
        {
            FixedAssert fa = this.fixedAssetsInBindingSource.Current as FixedAssert;
            if (fa != null)
            {
                m_assetsin.Remove(fa);
                m_assets.Add(fa);
            }
        }

        private void FixedAssetInDlg_Load(object sender, EventArgs e)
        {
            m_assets = FixedAssets.GetCheckoutList();
            m_assetsin = buildingLib.Administration.FixedAssetsIn.NewFixedAssetsIn();
            this.fixedAssetsInBindingSource.DataSource = m_assetsin;
            this.fixedAssetsBindingSource.DataSource = m_assets;
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            this.fixedAssetsInBindingSource.RaiseListChangedEvents = false;
            fixedAssetsInBindingSource.EndEdit();
            try
            {
                m_assetsin.Save();
            }
            catch (Csla.DataPortalException ex)
            {
                MessageBox.Show(ex.BusinessException.ToString(),
                  "Error saving", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(),
                  "Error Saving", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
            }
            finally
            {
                this.Close();
            }
        }
    }
}

